<?php

/*
 * Edit by shengxin
 * Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
 */
namespace api\mall\task;

use api\portal\model\UserModel;
/**
 * 签到任务
 *
 * @author PC
 */
class SignInTask extends BaseTask{
    
    public function check_comp($task) {
        return true;
    }
    
    public function get_reward($uid,$date){
        $time = time();
        if(is_string($date)){
            $time = strtotime($date);
        }
        $week = date('w',$time);//其中 0 表示星期日，1 表示星期一，依此类推，直到 6 表示星期六
        $weekName = ['周日','周一','周二','周三','周四','周五','周六'][$week];
        $week -= 1;
        if($week<0){
            $week = 6;
        }
        $rwcfg = cmf_get_option('mall_sign_in');
        $score = $rwcfg[$week];
        $desc = '完成签到任务:'.$weekName.',领取任务奖励';
        $model = new UserModel();
        $model->add_score($uid, $score, $desc,'task');
        $model->addTaskLog($uid, $score, $desc);
        $this->reward = $score;
    }
    
    public function calcReward($date){
        $time = time();
        if(is_string($date)){
            $time = strtotime($date);
        }
        $week = date('w',$time);//其中 0 表示星期日，1 表示星期一，依此类推，直到 6 表示星期六
        $week -= 1;
        if($week<0){
            $week = 6;
        }
        $rwcfg = cmf_get_option('mall_sign_in');
        $score = $rwcfg[$week];
        $this->reward = $score;
        return $score;
    }
}
